package Mysql_;

import Util.DBUtil;

import java.sql.*;

/**
 * @Author 汤舒青
 * @Version 1.0
 */

//统计各种性别的人数，并输出
public class Mysql01 {
    public static void main(String[] args) {
        Connection con = null;
        Statement st = null;
        ResultSet re = null;
        try {
            con = DBUtil.getConnection();
            st = con.createStatement();
            re = st.executeQuery("select sex,count(*) from s_student  GROUP BY sex;");
            while (re.next()) {
                String sex = re.getString("sex");
                int i = re.getInt(2);
                System.out.println("性别："+sex + " 人数"+i);

            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            DBUtil.close(re);
            DBUtil.close(st);
            DBUtil.close(con);
        }


    }
}